<template>
  <div>
    <div style="margin: 10px 0;">
      <el-input placeholder="请输入姓名查询" v-model="nickName" clearable style="width: 200px"></el-input>
      <el-input placeholder="请输入手机号查询" v-model="phone" clearable style="width: 200px;margin-left: 5px"></el-input>
      <el-input placeholder="请输入地址查询" v-model="address" clearable style="width: 200px;margin-left: 5px"></el-input>
      <el-button type="primary" icon="el-icon-search" style="margin-left: 5px" @click="search">查询</el-button>
      <el-button type="warning" icon="el-icon-refresh" style="margin-left: 5px" @click="reset">重置</el-button>
    </div>
    <div style="margin: 10px 0;">
      <el-button type="danger" icon="el-icon-delete" @click="delBatch">批量移除</el-button>
      <el-button type="primary" icon="el-icon-plus" @click="$router.push('/record')">查看打卡记录</el-button>
      <el-select v-model="localName" placeholder="请选择学校" @change="select" style="margin-left: 10px">
        <el-option
            v-for="item in localNames" :key="item.localeName" :label="item.localeName" :value="item.localeName">
        </el-option>
      </el-select>
    </div>


    <el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%"
              :header-cell-style="{background:'#e7e8ef',color:'#4f5257'}"
              stripe fixed border>
      <el-table-column
          prop="id"
          type="selection"
          width="40">
      </el-table-column>
      <el-table-column prop="nickName" label="姓名">
      </el-table-column>
      <el-table-column prop="phone" label="手机号">
      </el-table-column>
      <el-table-column prop="idCard" label="身份证">
      </el-table-column>
      <el-table-column prop="localName" label="学校">
      </el-table-column>
      <el-table-column prop="address" label="地址">
      </el-table-column>
      <el-table-column
          label="操作"
          width="220">
        <template slot-scope="scope">
          <el-popconfirm
              style="margin-left: 5px"
              confirm-button-text='确定'
              cancel-button-text='取消'
              icon="el-icon-info"
              icon-color="red"
              title="您确定移除学生吗？"
              @confirm="handleDelete(scope.$index, scope.row)"
          >
            <el-button type="danger" size="mini" class="el-icon-remove-outline" slot="reference">移除</el-button>
            <el-button type="success" size="mini"  slot="reference" @click="$router.push('/ReportDetail?id=' +scope.row.id)">健康打卡记录</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>

    </el-table>
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "SchoolStudentInfo",
  data(){
    return{
      phone:"",
      nickName:"",
      address:"",
      tableData:[],
      currentPage: 4,
      pageNum:0,
      pageSize:5,
      total:0,
      dialogVisible: false,
      form: {},
      ids:[],
      multipleSelection: [],
      roles: [],
      localNames:[],
      localName:""
    }
  },
  created() {
    this.load()
  },
  methods:{
    reset(){
      this.address="";
      this.phone="";
      this.nickName="";
      this.load()
      this.$message({
        message: '重置成功',
        type: 'success'
      });
    },
    search(){
      if (this.address!='' || this.nickName!='' || this.phone!=''){
        this.load()
        this.$message({
          message: '查询成功',
          type: 'success'
        });
      }else{
        this.$message({
          message: '请输入查询内容',
          type: 'warning'
        });
      }
    },
    select(){
      this.load()
    },
    load(){
      this.request.get("/user/schoolPage",{
            params:{
              pageNum:this.pageNum,
              pageSize:this.pageSize,
              nickName:this.nickName,
              address:this.address,
              localName:this.localName,
              phone:this.phone
            }
          }
      ).then(res =>{
        this.tableData=res.data.records
        this.total=res.data.total
      })
      //获取系统的学校地点名
      this.request.get("/localName/byLocale/"+"学校").then(res =>{
        this.localNames = res.data
      })
    },
    handleDelete(index, row) {
      this.request.post("/user/schoolDelete/"+(index,row).id).then(res=>{
        if (res.code === 200){
          this.load()
          this.$message({
            type: 'success',
            message: '移除成功!'
          });
        }
      })
    },
    delBatch(){
      let ids = this.multipleSelection.map(v =>v.id)
      if (ids.length!=0){
        this.$confirm('你正在进行批量移除操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.request.post("/user/batch/schoolDelete/", ids).then(res => {
            if (res.code === 200){
              this.load()
              this.$message({
                type: 'success',
                message: '批量删除成功!'
              });
            }else {
              this.$message({
                type: 'error',
                message: '删除失败!'
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }else {
        this.$message.warning("请选择删除记录")
      }
    },
    /**
     * 选择框
     * */
    handleSelectionChange(val) {
      this.multipleSelection = val;
      for (let i=1; i<=val; i++)
        console.log(this.multipleSelection[i])
    },
    /**
     * 自定义操作列
     * @param index
     * @param row
     */


    handleSizeChange(val) {
      this.pageSize = val;
      this.load()
    },
    handleCurrentChange(val) {
      this.pageNum=val
      this.load()
    }
  }
}
</script>

<style scoped>

</style>